load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Nix
http_archive(
    name = "io_tweag_rules_nixpkgs",
    sha256 = "532634d78c35a42745bc1ceb02193c1505e676ed55746947061c2b6bb37b85fb",
    strip_prefix = "rules_nixpkgs-c871abcedf5734513f7ab731ea6ba541636f4df6",
    urls = ["https://github.com/tweag/rules_nixpkgs/archive/c871abcedf5734513f7ab731ea6ba541636f4df6.tar.gz"],
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")

rules_nixpkgs_dependencies()

load("//bazel:nix_repositories.bzl", "nix_repositories")

nix_repositories()

# Toolchains
register_toolchains(
    "//bazel/toolchains/cc/aarch64-apple-darwin:toolchain",
    "//bazel/toolchains/cc/aarch64-apple-ios:toolchain",
    "//bazel/toolchains/cc/aarch64-linux-android:toolchain",
    "//bazel/toolchains/cc/aarch64-unknown-linux-gnu:toolchain",
    "//bazel/toolchains/cc/wasm32-unknown-unknown:toolchain",
    "//bazel/toolchains/cc/wasm32-wasi:toolchain",
    "//bazel/toolchains/cc/x86_64-apple-darwin:toolchain",
    "//bazel/toolchains/cc/x86_64-pc-windows-msvc:toolchain",
    "//bazel/toolchains/cc/x86_64-unknown-linux-gnu:toolchain",
    "//bazel/toolchains/cc/x86_64-unknown-nixos-gnu:toolchain",
    "//bazel/toolchains/rust/aarch64-apple-darwin:toolchain",
    "//bazel/toolchains/rust/aarch64-apple-ios:toolchain",
    "//bazel/toolchains/rust/aarch64-linux-android:toolchain",
    "//bazel/toolchains/rust/aarch64-unknown-linux-gnu:toolchain",
    "//bazel/toolchains/rust/wasm32-unknown-unknown:toolchain",
    "//bazel/toolchains/rust/wasm32-wasi:toolchain",
    "//bazel/toolchains/rust/x86_64-apple-darwin:toolchain",
    "//bazel/toolchains/rust/x86_64-pc-windows-msvc:toolchain",
    "//bazel/toolchains/rust/x86_64-unknown-linux-gnu:toolchain",
    "//bazel/toolchains/rust/x86_64-unknown-nixos-gnu:toolchain",
)

# Rust
local_repository(
    name = "rules_rust",
    path = "../..",
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains(
    edition = "2021",
)

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies(bootstrap = True)

load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "render_config", "splicing_config")
load("//bazel/cargo:crates_repository.bzl", CARGO_ANNOTATIONS = "ANNOTATIONS", CARGO_PACKAGES = "PACKAGES")

crates_repository(
    name = "crate_index",
    annotations = CARGO_ANNOTATIONS,
    cargo_lockfile = "//bazel/cargo:Cargo.lock",
    generate_build_scripts = False,
    generator = "@cargo_bazel_bootstrap//:cargo-bazel",
    lockfile = "//bazel/cargo:cargo-bazel-lock.json",
    packages = CARGO_PACKAGES,
    render_config = render_config(
        default_alias_rule = "opt",
    ),
    splicing_config = splicing_config(
        resolver_version = "2",
    ),
    supported_platform_triples = [
        "aarch64-apple-darwin",
        "aarch64-apple-ios",
        "aarch64-linux-android",
        "aarch64-unknown-linux-gnu",
        "wasm32-unknown-unknown",
        "wasm32-wasi",
        "x86_64-apple-darwin",
        "x86_64-pc-windows-msvc",
        "x86_64-unknown-linux-gnu",
        "x86_64-unknown-nixos-gnu",
    ],
)

load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()
